package com.warm.base.algorithm.sort;

/**
 * 排序抽象类
 */
public abstract class AbstractAscSort {

    public abstract void sort(Comparable[] a);

    protected static boolean less(Comparable v, Comparable w){
        return v.compareTo(w) < 0;
    }

    protected static void exch(Comparable[] a, int i, int j){
        Comparable t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    protected static void show(Comparable[] a){
        for (int i=0; i < a.length; i++){
            if(i == 0)
                System.out.print(a[i]);
            else
                System.out.print(", " + a[i]);
        }
    }

    protected static boolean isSorted(Comparable[] a){
        for (int i = 0; i < a.length; i++) {
            if(less(a[i], a[i-1])) return false;
        }
        return true;
    }
}
